<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>按钮 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
<link rel="stylesheet" href="layui/css/layui.css" media="all" />
<link rel="stylesheet" href="css/public.css" media="all" />
</head>
 
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-toolbar clearfix">
          <form class="pull-right search-bar" method="get" action="#!" role="form">
            <div class="input-group">
              <div class="input-group-btn">
                <input type="hidden" name="search_field" id="search-field" value="title">
                <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                标题 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                  <li> <a tabindex="-1" href="javascript:void(0)" data-field="title">标题</a> </li>
                  <li> <a tabindex="-1" href="javascript:void(0)" data-field="cat_name">栏目</a> </li>
                </ul>
              </div>
              <input type="text" class="form-control" value="" name="keyword" placeholder="请输入名称">
            </div>
          </form>
          <div class="toolbar-btn-action">
            <a class="btn btn-primary m-r-5" href="#!"><i class="mdi mdi-plus"></i> 新增</a>
            <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>
          </div>
        </div>
        <div class="card-body">
          
          <div class="table-responsive">
            <table class="table table-bordered">
              <thead>
                <tr>
                  <th>
                    <label class="lyear-checkbox checkbox-primary">
                      <input type="checkbox" id="check-all"><span></span>
                    </label>
                  </th>
                  <th>电影类别编号</th>
                  <th>电影类别名称</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <label class="lyear-checkbox checkbox-primary">
                      <input type="checkbox" name="ids[]" value="1"><span></span>
                    </label>
                  </td>
                  <td>1</td>
                  <td>爱情</td>
                  <td>
                    <div class="btn-group" id="barCar">
                      <a class="btn btn-xs btn-default" href="#!" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                      <a class="btn btn-xs btn-default" href="#!" title="查看" data-toggle="tooltip"><i class="mdi mdi-eye"></i></a>
                      <a class="btn btn-xs btn-default" href="#!" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>
                    </div>
                  </td>
                </tr>
                
              </tbody>
            </table>
            
            <!--<%--查看大图弹出的层开始--%>-->
					<div id="viewCarImageDiv" style="display: none;text-align: center">
					    <img alt="车辆图片" width="700px" height="310px" id="view_carimg" src="">
					</div>
          </div>
          <ul class="pagination">
            <li class="disabled"><span>«</span></li>
            <li class="active"><span>1</span></li>
            <li><a href="#1">2</a></li>
            <li><a href="#1">3</a></li>
            <li><a href="#1">4</a></li>
            <li><a href="#1">5</a></li>
            <li><a href="#1">6</a></li>
            <li><a href="#1">7</a></li>
            <li><a href="#1">8</a></li>
            <li class="disabled"><span>...</span></li>
            <li><a href="#!">14452</a></li>
            <li><a href="#!">14453</a></li>
            <li><a href="#!">»</a></li>
          </ul>
 
        </div>
      </div>
    </div>
    
  </div>
  
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
<script type="text/javascript">
$(function(){
    $('.search-bar .dropdown-menu a').click(function() {
        var field = $(this).data('field') || '';
        $('#search-field').val(field);
        $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
    });
});
</script>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>

<script>
    var menuTable;
    var url;
    layui.use(['layer','jquery','table','form'], function(){
        var layer = layui.layer,
            $ = layui.jquery;
        var table = layui.table;
        var form = layui.form;

        $("#doExport").click(function () {
            window.location.href="/cusExport?"+$("#searchFrm").serialize()
        })

        menuTable = table.render({
            elem: '#customerTable'
            ,url:'${pageContext.request.contextPath}/customerfind/'
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,cols: [[
                {type: 'checkbox',class:'identity', LAY_CHECKED:false,filter:'test', fixed: 'left'}
                ,{field:'identity', width:80, title: '身份证', sort: true}
                ,{field:'custname', width:80, title: '客户名称', sort: true}
                ,{field:'sex', width:80, title: '性别' }
                ,{field:'address', width:80, title: '地址'}
                ,{field:'phone', width:80, title: '联系方式'}
                ,{field:'career', width:80, title: '公司职位'}
                ,{field:'createtime', width:80, title: '创建时间'}
                ,{fixed: 'right', title:'操作', toolbar: '#barCustomer', width:150}
            ]]
            ,toolbar: '#toolbarCustomer' //开启头部工具栏，并为其绑定左侧模板
            ,page: ['5','10']
            ,limit:5
            ,id:'tableAll'
        });

        //头工具栏事件
        table.on('toolbar(customerTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'customerAdd':
                    add()
                    break;
                case 'delBatch':
                    deteall()
                    break;

            };
        });

        function add(){
            openIndex =  layer.open({
                type:1
                ,content:$('#saveOrUpdateDiv')
                ,title:"菜单添加"
                ,area:['800px', '450px']
                ,success:function (layero, index) {
                    // 清除表单的内容
                    $("#dataFrm").get(0).reset()
                    $("#pid").val("")
                    form.render()
                    url = "/addCustomer"
                }
            })
        }

        //批量删除
        function deteall() {
            debugger
            var checkStatus = table.checkStatus('tableAll');
            var checkData = checkStatus.data;
            var delList =new Array();
                if (checkData == "") {
                    layer.msg("至少选择一个")
                    return;
                }
                if (checkData.length > 0) {
                    for (var i = 0; i < checkData.length; i++) {
                        delList.push(checkData[i].identity);
                    }
                    $.ajax({
                        url: "/deleall/"+delList,
                        dataType: 'json',
                        success: function (data) {
                            if (data == 0) {
                                layer.msg('删除失败！', {icon: 5, offset: "auto", time: 2000});//提示框
                            } else {
                                layer.msg('删除成功！', {icon: 6, offset: "auto", time: 2000});//提示框
                            }
                            location.reload();//重新加载页面表格

                        }
                    });
                }
        }




        //监听行工具事件
        table.on('tool(customerTable)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){

                    del(data.identity)
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                edit(data)
            }
        });
        function del(identity) {
            $.post("/delCustomer",{"identity":identity},function (d) {
                layer.msg(d.msg, {
                    offset: '50px'
                    ,icon: 1
                    ,time: 1000
                }, function(){
                    // 刷新table
                    menuTable.reload({
                        page:{curr:1}
                    })
                });
            })
        }

        function edit(data) {
            openIndex =  layer.open({
                type:1
                ,content:$('#saveOrUpdateDiv')
                ,title:"菜单修改"
                ,area:['800px', '450px']
                ,offset:'50px'
                ,success:function (layero, index) {
                    // 给表单设置值
                    form.val('dataFrm',data)
                    debugger
                    $('[name="custname"]').val(data.custname)
                    $('#sex').val(data.sex)
                    $('#address').val(data.address)
                    $('#phone').val(data.phone)
                    $('#career').val(data.career)
                    $('#identity').val(data.identity)
                    form.render()
                    url = "/updateCustomer"
                }
            })
        }

        form.on("submit(doSearch)",function (data) {
            menuTable.reload({
                page:{curr:1}
                ,where:data.field
            })

            return false;
        })


        form.on("submit(doSubmit)",function (data) {

            console.info(data.field)
            $.post(url,data.field,function (d) {
                layer.msg(d.msg, {
                    offset: '50px'
                    ,icon: 1
                    ,time: 1000
                }, function(){
                    // 关闭当前弹出框
                    layer.close(openIndex)
                    // 刷新table
                    menuTable.reload({
                        page:{curr:1}
                    })
                    // 刷新左侧tabletree
                    window.parent.left.demoTree.reload()
                    // 下拉菜单也要刷新
                    menuTree.reload()
                });
            })

            return false;
        })






    });


</script>
</html>